package mongodb

import (
	"github.com/Sir-yuChen/funAnalyse/global"
)

var (
	CommunicationUserCollection            BaseCollection
	CommunicationRoomCollection            BaseCollection
	CommunicationRoomMemberCollection      BaseCollection
	CommunicationUserRoomCollection        BaseCollection
	CommunicationSingleUserCollection      BaseCollection
	CommunicationBaseInformationCollection BaseCollection
	CommInformationOnUserCollection        BaseCollection
)

func InitMongoDBCollection() {
	//ctx := context.TODO()
	CommunicationUserCollection = CreateMongoCollection("stock", "communication_user")                        //用户好友通讯录
	CommunicationRoomCollection = CreateMongoCollection("stock", "communication_room")                        //聊天室基础信息
	CommunicationUserRoomCollection = CreateMongoCollection("stock", "communication_user_room")               //聊天室关于用户的个性设置信息
	CommunicationSingleUserCollection = CreateMongoCollection("stock", "communication_single_user")           //用户私聊关系表
	CommunicationBaseInformationCollection = CreateMongoCollection("stock", "communication_base_Information") //基础消息
	CommInformationOnUserCollection = CreateMongoCollection("stock", "information_on_user")                   //用户关于消息表
	CommunicationRoomMemberCollection = CreateMongoCollection("stock", "communication_room_member")           //聊天室成员表
	/*	// 初始化索引
		indexes := []mongo.IndexModel{
			{
				Keys:    bson.D{{"name", 1}, {"age", -1}},
				Options: options.Index().SetUnique(true),
			},
		}
		if err := communicationRoomCollection.CreateIndexes(ctx, indexes); err != nil {
			fmt.Printf("init indexes error: %v", err.Error())
		}*/
}

func CreateMongoCollection(dbName, colName string) BaseCollection {
	dataBase := global.GVA_MongoDB.Database(dbName)
	return &BaseCollectionImpl{
		DbName:     dbName,
		ColName:    colName,
		DataBase:   dataBase,
		Collection: dataBase.Collection(colName),
	}
}
